

/*
 * song.c
 *
 *  Created on: Feb 27, 2013
 *      Author: Vincent & Jimmy
 */
#include "support_common.h" /* include peripheral declarations and more */
#include <stdio.h>
#include "song.h"
#include "note.h"
#include "pwm.h"
#include "pushb.h"

Song JingleBells;
int note_i;

void song_init()
{
        JingleBells.note[0] = create_note(Pitch_E4, Duration_Quarter);
        JingleBells.note[1] = create_note(Pitch_E4, Duration_Quarter);
        JingleBells.note[2] = create_note(Pitch_E4, Duration_Half);
       
        JingleBells.note[3] = create_note(Pitch_E4, Duration_Quarter);
        JingleBells.note[4] = create_note(Pitch_E4, Duration_Quarter);
        JingleBells.note[5] = create_note(Pitch_E4, Duration_Half);
       
        JingleBells.note[6] = create_note(Pitch_E4, Duration_Quarter);
        JingleBells.note[7] = create_note(Pitch_G4, Duration_Quarter);
        JingleBells.note[8] = create_note(Pitch_C4, Duration_Quarter);
        JingleBells.note[9] = create_note(Pitch_D4, Duration_Quarter);
       
        JingleBells.note[10] = create_note(Pitch_E4, Duration_Whole);
       
        JingleBells.note[11] = create_note(Pitch_F4, Duration_Quarter);
        JingleBells.note[12] = create_note(Pitch_F4, Duration_Quarter);
        JingleBells.note[13] = create_note(Pitch_F4, Duration_Quarter);
        JingleBells.note[14] = create_note(Pitch_F4, Duration_Quarter);
       
        JingleBells.note[15] = create_note(Pitch_F4, Duration_Quarter);
        JingleBells.note[16] = create_note(Pitch_E4, Duration_Quarter);
        JingleBells.note[17] = create_note(Pitch_E4, Duration_Quarter);
        JingleBells.note[18] = create_note(Pitch_E4, Duration_Quarter);
       
        JingleBells.note[19] = create_note(Pitch_E4, Duration_Quarter);
        JingleBells.note[20] = create_note(Pitch_D4, Duration_Quarter);
        JingleBells.note[21] = create_note(Pitch_D4, Duration_Quarter);
        JingleBells.note[22] = create_note(Pitch_E4, Duration_Quarter);
       
        JingleBells.note[23] = create_note(Pitch_D4, Duration_Half);
        JingleBells.note[24] = create_note(Pitch_G4, Duration_Half);
       
}


void play_JB()
{		
		if(note_i ==25)
		{
			note_i=0;
		}
        Note noteplaying = JingleBells.note[note_i];
        set_pitch(noteplaying);
        set_duration(noteplaying);
        MCF_GPT_GPTFLG1 |= 0x01;
        play_note();
        note_i += 1;
       
}

void play_delay(Note delaynote)
{
        set_pitch(delaynote);
        set_delay(BPM);
        MCF_GPT_GPTFLG1 |= 0x01;
        play_note();
}
